package com.holly.unit.kafka.starter;

import com.holly.unit.kafka.KafkaApi;
import com.holly.unit.kafka.KafkaMetaApi;
import com.holly.unit.kafka.config.KafkaConfig;
import com.holly.unit.kafka.impl.KafkaApiImpl;
import com.holly.unit.kafka.impl.KafkaMetaApiImpl;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * kafka 自动配置
 * @author yangpengpeng
 *
 */
@Configuration
public class KafkaAutoConfiguration {

	@Bean
	@ConditionalOnMissingBean(KafkaApi.class)
	public KafkaApi kafkaApi() {
		return new KafkaApiImpl(kafkaConfig());
	}
	@Bean
	@ConditionalOnMissingBean(KafkaMetaApi.class)
	public KafkaMetaApi kafkaMetaApi() {
		return new KafkaMetaApiImpl(kafkaConfig());
	}
	@Bean
	@ConfigurationProperties(prefix = "holly.kafka")
	public KafkaConfig kafkaConfig() {
		return new KafkaConfig();
	}
}
